local AppleFactory = class("Apple")

function AppleFactory:ctor(bound, node)
    self.bound = bound
    self.node = node

    math.randomseed(os.time())

    self:Generate()
end

function AppleFactory:Generate( )
	if self.appleSprite ~= nil then
		self.node:removeChild(self.appleSprite)
	end

	local sp = cc.Sprite:create("apple.png")	

	local x, y = RandomEmptyPos(self.bound)
	local finalX, finalY = Grid2Pos(x, y)

	sp:setPosition(finalX, finalY)
	self.node:addChild(sp)

	SetCollide(x, y, { Name = "apple" })

	self.appleX, self.appleY = x, y
	self.appleSprite = sp
end

function AppleFactory:Reset( )
	self.node:removeChild(self.appleSprite)
end

return AppleFactory